package main

import (
	"sync"
	"fmt"
	"unsafe"
)

/*
  单例模式，该类型只有唯一的对象
*/


var once sync.Once
//实例
var instance singleton
//类型
type singleton struct {
}

func GetInstance() singleton {

	once.Do(func() {
		//确保只执行一次
		instance = singleton{}
	})
	return instance
}

func main() {
	inst1 := GetInstance()
	fmt.Println(unsafe.Pointer(&inst1))
	inst2 := GetInstance()
	fmt.Println(unsafe.Pointer(&inst2))
}